<template>
    <div class="save-wawa">
      <div class="account-area">
        <div class="account-txt">用户账号：</div>
        <input class="account-edit" placeholder="请输入用户ID"  v-model="uid"/>
        <div class="account-right" @click="checkUser">查找</div>
      </div>
      <div class="line"></div>
      <div class="num-area">
        <div class="num-txt">存入数量：</div>
        <input class="num-edt" placeholder="请输入存入娃娃的数量" v-model="num"/>
      </div>
      <div class="line"></div>
      <div class="user-area" v-if="show">
        <img :src="userhead" class="user-head"/>
        <div class="user-info">
          <div class="user-name">{{name}}</div>
          <div class="user-doll">娃娃个数：{{doll}}个</div>
        </div>
      </div>
      <div class="submit" @click="submit">提交</div>
      <!--<UserInfo-->
        <!--v-if="show"-->
        <!--:userhead="userhead"-->
        <!--:username="name"-->
        <!--:onSureClick="closeUser"/>-->
      <DialogWindow
        v-if="isDialogShow"
        :content="errmsg"
        showbtncode="1"
        :onCloseClick="onDialogCloseClick"/>

    </div>
</template>

<script>
  import {getUser} from '@/api/api'
  import {recharge} from '@/api/api'
  import UserInfo from '@/components/UserInfo'
  import DialogWindow from '@/components/DialogWindow'
    export default {

      created(){

      },
      data(){
        return{
          uid:'',
          num:0,
          show:false,
          userhead:'',
          name:'',
          isDialogShow:false,
          errmsg:null,
          doll:0,
          rechargeSuc:false
        }
      },
        name: "save-wawa",
      components:{
        UserInfo,
        DialogWindow
      },
      methods: {
        checkUser() {
          if (this.uid.length == 0) {
            return
          }
          this.show = false
          let params = {
            filter: {
              uid: this.uid // 用户UID或者昵称
            }

          }

          getUser(params).then(res => {
            if (res.code == 0) {
              this.show = true
              this.userhead = res.data.avatar
              this.name = res.data.nickname
              this.doll = res.data.doll
            } else {
              this.isDialogShow=true
              this.errmsg=res.message
            }
          })


        },
        submit() {
          let params = {
            user_id: this.uid,
            doll: this.num
          }
          recharge(params).then(res => {
            if (res.code == 0) {
              this.rechargeSuc = true
              this.isDialogShow=true
              this.errmsg='充值成功'
            }else{
              this.rechargeSuc = false
              this.isDialogShow=true
              this.errmsg=res.message
            }
          })
        },
        closeUser() {
          this.show = false

        },
        onDialogCloseClick () {
          if (this.rechargeSuc){
            this.checkUser()
          }
          this.isDialogShow=false;

        }
      }
    }
</script>

<style scoped>
  input{
    border: 0;
    outline: none;
  }
  .save-wawa{
    position: absolute;
    width: 100%;
    height: 100%;
    background:rgba(239,239,244,1);
    padding-top: 15px;
  }
  .account-area{
    width: 100%;
    height: 60px;
    background: #fff;
  }
  .account-txt{
    font-size:17px;
    font-family:PingFangSC-Light;
    font-weight:300;
    color:rgba(51,51,51,1);
    line-height:60px;
    float: left;
    margin-left: 15px;
    margin-right: 9px;
  }
  .account-edit{
    max-width: 180px;
    font-size:17px;
    font-family:PingFangSC-Light;
    font-weight:300;
    color:rgba(51,51,51,1);
    line-height:42px;
    margin-top: 9px;
    float: left;
  }
  .account-right{
    width:52px;
    height:26px;
    border-radius:8px;
    border:1px solid rgba(75,172,255,1);
    font-size:17px;
    font-family:PingFangSC-Light;
    font-weight:300;
    color:rgba(75,172,255,1);
    line-height:26px;
    float: right;
    margin-right: 15px;
    margin-top: 17px;
    text-align: center;
  }
  .line{
    width:100%;
    height:1px;
    background:rgba(229,229,229,1);
  }
  .num-area{
    width: 100%;
    height: 60px;
    background: #fff;
  }
  .num-txt{
    font-size:17px;
    font-family:PingFangSC-Light;
    font-weight:300;
    color:rgba(51,51,51,1);
    line-height:60px;
    float: left;
    margin-left: 15px;
    margin-right: 9px;
  }
  .num-edt{
    font-size:17px;
    font-family:PingFangSC-Light;
    font-weight:300;
    color:rgba(51,51,51,1);
    line-height:42px;
    float: left;
    margin-top: 9px;
  }
  .submit{
    width: 90%;
    height: 47px;
    background:rgba(254,108,136,1);
    border-radius:5px;
    font-size:17px;
    font-family:PingFangSC-Light;
    font-weight:300;
    color:rgba(255,255,255,1);
    line-height:47px;
    text-align: center;
    margin: 0 auto;
    margin-top: 30px;
  }

  .user-area{
    width: 100%;
    height: 90px;
    background: #fff;
  }

  .user-head{
    width: 70px;
    height: 70px;
    border-radius: 50%;
    margin-top: 10px;
    margin-left: 15px;
    margin-right: 10px;
    float: left;

  }
  .user-info{
    width: auto;
    height: 90px;
    float: left;
  }

  .user-name{
    font-size:18px;
    font-family:PingFangSC-Regular;
    font-weight:400;
    color:rgba(51,51,51,1);
    line-height:24px;
    margin-top: 12px;
    text-align: left;
  }

  .user-doll{
    font-size:16px;
    font-family:PingFangSC-Regular;
    font-weight:400;
    color:rgba(51,51,51,1);
    line-height:24px;
    margin-top: 18px;
    text-align: left;
  }


</style>
